package com.shaozj.auth.controller;

import com.shaozj.captcha.model.CaptchaResult;
import com.shaozj.core.result.Result;
import com.shaozj.auth.model.form.PasswordLoginForm;
import com.shaozj.auth.model.form.RegisterForm;
import com.shaozj.auth.model.form.SocialLoginForm;
import com.shaozj.auth.model.vo.LoginVO;
import com.shaozj.auth.model.vo.UserAuthInfoVO;
import com.shaozj.auth.service.AuthService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

@RequiredArgsConstructor
@Tag(name = "01.登录授权接口")
@RestController
@RequestMapping("/api/v1/auth")
public class AuthController {

    private final AuthService authService;

    @Operation(summary = "登录")
    @PostMapping("/login")
    public Result<LoginVO> doLogin(@ParameterObject @RequestBody PasswordLoginForm loginForm) {
        return Result.success(authService.login(loginForm));
    }

    @Operation(summary = "获取验证码")
    @GetMapping("/captcha")
    public Result<CaptchaResult> getCaptcha() {
        return Result.success(authService.getCaptcha());
    }

    @Operation(summary = "退出登录")
    @GetMapping("/logout")
    public Result logout() {
        authService.logout();
        return Result.success();
    }

    @Operation(summary = "用户注册")
    @GetMapping("/register")
    public Result register(@RequestBody  RegisterForm registerForm) {
        return null;
    }

    @Operation(summary = "获取当前登录用户")
    @GetMapping("/getInfo")
    public Result<UserAuthInfoVO> getUserInfo() {
        return Result.success(authService.getUserInfo());
    }



//    @Operation(summary = "注册用户")
//    @PostMapping("/register")
//    public Result register(@RequestBody @Valid UserRegisterForm registerForm) {
//        return Result.judge(userService.registerUser(registerForm));
//    }
//    @Operation(summary = "发送注册短信验证码")
//    @PostMapping("/register/sms_code")
//    public Result sendRegisterSmsCode(@Parameter(description = "手机号") @RequestParam(required = true) String mobile) {
//        return Result.judge(userService.senRegistSmsCode(mobile));
//    }









    @Operation(summary = "第三方登录请求")
    @GetMapping("/binding/{source}")
    public Result authBind(@Parameter(description = "登录来源")  @PathVariable String source,
                                   @Parameter(description = "租户ID") String tenantId,
                                   @Parameter(description = "域名") String domain) {
        return null;
    }

    @Operation(summary = "第三方登录回调业务处理，绑定授权")
    @GetMapping("/social/callback")
    public Result socialCallback(@RequestBody SocialLoginForm loginBody) {
        return null;
    }

    /**
     * 取消授权
     * @param socialId
     * @return
     */
    @DeleteMapping("/unlock/{socialId}")
    public Result unlockSocial(@PathVariable Long socialId) {
        return null;
    }



//    public Result logout() {
//        // 注意执行顺序，最后再执行logout
//        // 清除缓存session
//        StpUtil.getTokenSession().logout();
//        // 退出登录
//        StpUtil.logout();
//        return Result.success();
//    }
}
